package com.dragon.modules.yuegou.service.impl.member;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.modules.yuegou.entity.member.TemplateColumnEntity;
import com.dragon.modules.yuegou.mapper.member.TemplateColumnMapper;
import com.dragon.modules.yuegou.model.member.TemplateColumn;
import com.dragon.modules.yuegou.query.member.TemplateColumnQuery;
import com.dragon.modules.yuegou.service.member.TemplateColumnService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 会员模板栏位信息 服务实现
 *
 * @author pbuilder generated
 * @date 2021-10-26 20:30:59
 * @version 2.0
 */
@Service("memTemplateColumnService")
public class TemplateColumnServiceImpl
		extends ServiceImpl<TemplateColumnMapper, TemplateColumnEntity>
		implements TemplateColumnService {

	@Override
	public void saveTemplateColumnList(String templateSetId, List<TemplateColumn> templateColumnList) {
		
		if(StringUtils.isNotBlank(templateSetId)) {
			TemplateColumnQuery query = new TemplateColumnQuery();
			query.setTemplateSetId(templateSetId);
			remove(query.toQueryWrapper());
		}
		for(TemplateColumn templateColumn : templateColumnList) {
			save(templateColumn);
		}		
	}

	@Override
	public List<TemplateColumn> getTemplateColumns(String templateSetId) {
		TemplateColumnQuery query = new TemplateColumnQuery();
		query.setTemplateSetId(templateSetId);
		return list(query.toQueryWrapper()).stream().map(TemplateColumn::new).collect(Collectors.toList());
	}

}